const Role  = require("../../model/role.model");
class RoleService {
  async getRole(args) {
    const { current = 1, pageSize = 10, ...remainingParameters } = args;
    const { rows: list } = await Role.findAndCountAll({
      where: {
        ...remainingParameters,
      },
      order: [["createdAt",'DESC']],
    });
    
    return {
      list,
    };
  }
  async addRole(args) {
    const { id, createdAt, is_it_enabled, updatedAt, ...remainingParameters } =
      args;
    const res = await Role.create(remainingParameters);
    return res;
  }
  async updateRole(args) {
    const { id, createdAt, updatedAt, ...remainingParameters } = args;
    const resource = await Role.update(
      {
        ...remainingParameters,
      },
      {
        where: {
          id,
        },
      }
    );
    return resource;
  }
  async deleteRole(args) {
    const { id } = args;
    const res = await Role.destroy({
      where: {
        id,
      },
    });
    return res;
  }
}

module.exports = new RoleService();
